<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2010 Ethan Gruber
    numishare: http://code.google.com/p/numishare/
    Apache License 2.0: http://code.google.com/p/numishare/    
-->
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ev="http://www.w3.org/2001/xml-events"
	xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:widget="http://orbeon.org/oxf/xml/widget" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
	xmlns:exist="http://exist.sourceforge.net/NS/exist" xmlns:xxi="http://orbeon.org/oxf/xml/xinclude" xmlns:numishare="http://code.google.com/p/numishare/" xmlns:xlink="http://www.w3.org/1999/xlink">
	<xhtml:head>
		<xhtml:title>Numishare: Administrative Interface</xhtml:title>
		<!-- Core + Skin CSS -->
		<xhtml:link rel="stylesheet" type="text/css" href="/apps/numishare/css/jquery-ui-1.8.10.custom.css"/>
		<xhtml:link rel="stylesheet" href="/apps/numishare/css/reset-fonts-grids.css"/>
		<xhtml:link rel="stylesheet" href="/apps/numishare/css/base-min.css"/>
		<xhtml:link rel="stylesheet" href="/apps/numishare/css/fonts-min.css"/>

		<!-- numishare styling -->
		<xhtml:link rel="stylesheet" href="/apps/numishare/css/xforms.css"/>

		<xhtml:script type="text/javascript" src="/apps/numishare/javascript/jquery-1.6.1.min.js"/>
		<xhtml:script type="text/javascript" src="/apps/numishare/javascript/numishare-menu.js"/>
		<xforms:model>
			<!-- exist URL is stored in an XML file -->
			<xforms:instance id="exist-url">
				<xi:include href="exist-url.xml"/>
			</xforms:instance>

			<xforms:instance id="control-instance">
				<controls xmlns="">
					<status/>
					<error/>
					<page>1</page>
					<solr-query>fulltext:*</solr-query>
					<solr-core/>
					<temp/>
					<collection-name/>
					<identifiers/>
					<nuds-count/>
					<nh-count/>
				</controls>
			</xforms:instance>

			<xforms:instance id="config">
				<config xmlns=""/>
			</xforms:instance>

			<xforms:instance id="collections-list">
				<collections xmlns="">
					<collection role="admin" name="numishare"/>
				</collections>
			</xforms:instance>

			<xforms:instance id="collection-template">
				<collection role="" name=""/>
			</xforms:instance>

			<xforms:instance id="config-template">
				<config xmlns:xlink="http://www.w3.org/1999/xlink">
					<firstrun/>
					<title>Numishare - Digital Artifactual Exhibition</title>
					<description>Enter short description for collection.</description>
					<banner_text/>
					<banner_image xlink:href="numishare-long.png"/>
					<url>http://localhost:8080/cocoon/numishare/</url>
					<solr_published>http://localhost:8080/solr/numishare-published/</solr_published>
					<solr_all>http://localhost:8080/solr/numishare-all/</solr_all>
					<flickr_api_key/>
					<geonames_api_key/>
					<contact/>
					<google_analytics>
						<script type="text/javascript"/>
					</google_analytics>
					<collection_type>object</collection_type>					
					<features_enabled>true</features_enabled>
					<pelagios_enabled>false</pelagios_enabled>
					<ctype_enabled>false</ctype_enabled>
					<template>
						<copyrightHolder/>
						<collection/>
						<language langcode=""/>
						<license>http://opendatacommons.org/licenses/odbl/</license>
						<owner/>
						<publisher/>
						<repository/>
						<project/>
						<createdBy/>
					</template>
					<images>
						<absolute_path>/usr/local/projects/numishare/cocoon/</absolute_path>
						<thumbnail>120</thumbnail>
						<reference>400</reference>
					</images>
					<languages>
						<language code="en" enabled="false">
							<label xml:lang="en">English</label>
							<label xml:lang="ar">إنجليزي</label>
						</language>
						<language code="ar" enabled="false">
							<label xml:lang="en">Arabic</label>
							<label xml:lang="ar">العربيّة</label>
						</language>
					</languages>
					<theme>
						<jquery_ui_theme>smoothness</jquery_ui_theme>
						<layouts>
							<index>
								<yui_class>yui-t5</yui_class>
							</index>
							<results>
								<yui_class>yui-t2</yui_class>
								<image_location>right</image_location>
							</results>
							<display>
								<nuds>
									<orientation>vertical</orientation>
									<image_location>left</image_location>
								</nuds>
							</display>
						</layouts>
					</theme>
					<footer>Powered by &lt;a href="http://code.google.com/p/numishare/" target="_blank"&gt;Numishare&lt;/a&gt;.</footer>
					<pages>
						<index>Numishare is a free, open source, modularized system of Tomcat applications for the web delivery of cultural heritage artifacts, with particular focus on coins and
						medals. Metadata are edited with XForms and delivered with Cocoon and Solr.</index>
						<compare enabled="true"/>
						<analyze enabled="false"/>
						<visualize enabled="true"/>
					</pages>
				</config>
			</xforms:instance>

			<xforms:instance id="imports-template">
				<imports/>
			</xforms:instance>
			<xforms:instance id="languageselect-template" src="/apps/numishare/instances/languages.xml"/>

			<xforms:instance id="create-object-collection">
				<exist:query xmlns="">
					<exist:text/>
				</exist:query>
			</xforms:instance>

			<xforms:instance id="eXist-xquery">
				<exist:query xmlns:exist="http://exist.sourceforge.net/NS/exist">
					<exist:text>&lt;report&gt;{count(collection())}&lt;/report&gt;</exist:text>
				</exist:query>
			</xforms:instance>

			<xforms:instance id="collection-result">
				<exist:result/>
			</xforms:instance>

			<xforms:instance id="list">
				<list xmlns=""/>
			</xforms:instance>

			<xforms:instance id="item-template">
				<item xmlns="">
					<title/>
					<id/>
					<recordType/>
					<obverseType/>
					<obverseLegend/>
					<reverseType/>
					<reverseLegend/>
					<thumbnail_obv/>
					<thumbnail_rev/>
					<published/>
				</item>
			</xforms:instance>

			<xforms:instance id="id">
				<id xmlns=""/>
			</xforms:instance>

			<xforms:instance id="object">
				<nuds xmlns=""/>
			</xforms:instance>

			<!-- solr response for id query -->
			<xforms:instance id="query-all-response">
				<response xmlns=""/>
			</xforms:instance>
			<xforms:instance id="published-response">
				<response xmlns=""/>
			</xforms:instance>
			<xforms:instance id="all-response">
				<response xmlns=""/>
			</xforms:instance>
			<xforms:instance id="list-published-response">
				<response xmlns=""/>
			</xforms:instance>
			<xforms:instance id="is-published">
				<response xmlns=""/>
			</xforms:instance>

			<!-- send to Solr -->
			<xforms:instance id="addIndex">
				<add xmlns=""/>
			</xforms:instance>
			<xforms:instance id="collection-field">
				<field name="collection-name"/>
			</xforms:instance>
			<!-- Instance for Solr commit-->
			<xforms:instance id="sendCommit">
				<commit/>
			</xforms:instance>

			<!-- Solr optimize -->
			<xforms:instance id="optimizeIndex">
				<optimize/>
			</xforms:instance>

			<!-- delete from Solr -->
			<xforms:instance id="deleteId">
				<delete xmlns="">
					<id/>
				</delete>
			</xforms:instance>
			<xforms:instance id="deleteAll">
				<delete xmlns="">
					<query/>
				</delete>
			</xforms:instance>

			<xforms:instance id="dump">
				<dump/>
			</xforms:instance>

			<!-- ************************* BINDINGS ************************** -->
			<xforms:bind nodeset="instance('collections-list')">
				<xforms:bind nodeset="collection">
					<xforms:bind nodeset="@name" required="true()" type="xs:ID"/>
				</xforms:bind>
			</xforms:bind>

			<xforms:bind nodeset="instance('config-template')">
				<xforms:bind nodeset="title" required="true()"/>
				<xforms:bind nodeset="banner_text"/>
				<xforms:bind nodeset="url" required="true()"/>
				<xforms:bind nodeset="solr_published" required="true()"/>
				<xforms:bind nodeset="solr_all" required="true()"/>
				<xforms:bind nodeset="template">
					<!-- about the electronic record -->
					<xforms:bind nodeset="publisher" required="true()"/>
					<xforms:bind nodeset="copyrightHolder" required="true()"/>
					<xforms:bind nodeset="createdBy"/>
					<xforms:bind nodeset="project"/>
					<xforms:bind nodeset="language">
						<xforms:bind constraint="string-length(@langcode) &gt; 0"/>
					</xforms:bind>
					<!-- about the physical item -->
					<xforms:bind nodeset="repository"/>
					<xforms:bind nodeset="owner"/>
					<xforms:bind nodeset="collection"/>
				</xforms:bind>
				<xforms:bind nodeset="images">
					<xforms:bind nodeset="thumbnail" required="true()" type="xs:integer"/>
					<xforms:bind nodeset="screen" required="true()" type="xs:integer"/>
				</xforms:bind>
			</xforms:bind>
			<!-- load collections/roles config -->
			<xforms:submission id="load-collections" serialization="none" method="get" action="{instance('exist-url')}collections-list.xml" replace="instance" instance="collections-list"
				xxforms:username="admin" xxforms:password="">
				<!-- if the config loads successfully, set the collection names based on authentication -->
				<xforms:action ev:event="xforms-submit-done">
					<!--<xforms:message ev:event="xforms-submit-error" level="modal">test</xforms:message>-->
					<!-- set default if security is false -->
					<xforms:action if="not(string(instance('control-instance')/request-security/role))">
						<xforms:setvalue ref="instance('control-instance')/collection-name">numishare</xforms:setvalue>
					</xforms:action>
					<!-- if there is a security role, set the collection-name value if it is in the list, otherwise set new collection name -->
					<xforms:action if="string(instance('control-instance')/request-security/role)">
						<xforms:action if="string(instance('collections-list')/collection[@role=instance('control-instance')/request-security/role]/@name)">
							<xforms:setvalue ref="instance('control-instance')/collection-name"
								value="instance('collections-list')/collection[@role=instance('control-instance')/request-security/role]/@name"/>
						</xforms:action>
						<xforms:action if="not(string(instance('collections-list')/collection[@role=instance('control-instance')/request-security/role]/@name))">
							<xforms:insert context="instance('collections-list')" nodeset="./child::node()[last()]" origin="instance('collection-template')"/>
							<xforms:setvalue ref="instance('collections-list')/collection[last()]/@role" value="instance('control-instance')/request-security/role"/>
						</xforms:action>
					</xforms:action>
					<!-- set exist collection value for creating new collection-->
					<xforms:setvalue ref="instance('create-object-collection')/exist:text"
						value="concat(&quot;xmldb:create-collection(&#x0027;/db/&quot;, instance(&quot;control-instance&quot;)/collection-name, &quot;&#x0027;, &#x0027;objects&#x0027;)&quot;)"/>
					<!-- set the delete all query -->
					<xforms:setvalue ref="instance('deleteAll')/query" value="concat('collection-name:', instance('control-instance')/collection-name)"/>
					<xforms:send submission="load-config"/>
				</xforms:action>
				<!-- if the config has not been created (given that the URL in exist-url.xml is correct), create it -->
				<xforms:action ev:event="xforms-submit-error">
					<!-- if there is no security, quietly save collections-list.xml -->
					<xforms:action if="not(string(instance('control-instance')/request-security/role))">
						<xforms:setvalue ref="instance('control-instance')/collection-name">numishare</xforms:setvalue>
						<xforms:send submission="save-collections"/>
					</xforms:action>
					<xforms:action if="string(instance('control-instance')/request-security/role)">
						<xforms:action if="not(instance('control-instance')/request-security/role='admin')">
							<xforms:insert context="instance('collections-list')" nodeset="./child::node()[last()]" origin="instance('collection-template')"/>
							<xforms:setvalue ref="instance('collections-list')/collection[last()]/@role" value="instance('control-instance')/request-security/role"/>
						</xforms:action>
					</xforms:action>
				</xforms:action>
			</xforms:submission>

			<xforms:submission id="save-collections" ref="instance('collections-list')" action="{instance('exist-url')}/collections-list.xml" method="put" replace="none" xxforms:username="admin"
				xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving Collections List.</xforms:message>
				<xforms:send submission="load-collections"/>
			</xforms:submission>

			<xforms:submission id="xquery-collection" ref="instance('eXist-xquery')" action="{instance('exist-url')}{instance('control-instance')/collection-name}/objects" method="post"
				replace="instance" instance="collection-result" xxforms:username="admin" xxforms:password="">
				<xforms:setvalue ref="instance('control-instance')/error" ev:event="xforms-submit-error">Error querying eXist database.</xforms:setvalue>
			</xforms:submission>

			<!-- submissions -->
			<xforms:submission id="load-config" serialization="none" method="get" action="{instance('exist-url')}{instance('control-instance')/collection-name}/config.xml" replace="instance"
				instance="config" xxforms:username="admin" xxforms:password="">
				<xforms:action ev:event="xforms-submit-done">
					<xforms:setvalue ref="instance('control-instance')/temp" value="concat(instance('exist-url'), instance('control-instance')/collection-name, '/objects')"/>
					<!-- get the number of docs in the eXist collection() -->
					<xforms:send submission="xquery-collection"/>
					<!-- query solr unpublished core for all docs, fulltext:* -->
					<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
					<xforms:send submission="query-all-docs"/>
					<!-- if there is a mismatch in documents between Solr index of all documents and the eXist collection, delete all docs from Solr and reidnex -->
					<xforms:action if="number(instance('query-all-response')/result/@numFound) != number(instance('collection-result'))">
						<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
						<xforms:message level="modal">Mismatch between Solr records and objects in eXist. Collection list flushed and reindexed.</xforms:message>
						<xforms:setvalue ref="instance('deleteAll')/query" value="concat('collection-name:', instance('control-instance')/collection-name)"/>
						<xforms:send submission="delete-all"/>
						<xforms:setvalue ref="instance('eXist-xquery')/exist:text">&lt;report> { for $foo in collection() return &lt;item> { $foo//*[local-name()='nudsHeader']/*[local-name()='nudsid']
							} &lt;/item> } &lt;/report></xforms:setvalue>
						<xforms:send submission="xquery-collection"/>
						<xforms:action xxforms:iterate="instance('collection-result')/report/item/*[local-name()='nudsid']">
							<xxforms:variable name="id" select="."/>
							<xforms:setvalue ref="instance('id')" value="$id"/>
							<xforms:send submission="load-object"/>
						</xforms:action>
						<!-- optimize index -->
						<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
						<xforms:send submission="optimize"/>
					</xforms:action>
					<!-- reload table -->
					<xforms:delete nodeset="instance('list')/*"/>
					<xforms:send submission="query-solr"/>
				</xforms:action>
				<!-- if config.xml doesn't exist, then create the exist collection with necessary files -->
				<xforms:action ev:event="xforms-submit-error">
					<xforms:setvalue ref="instance('config-template')/firstrun">true</xforms:setvalue>
				</xforms:action>
			</xforms:submission>

			<xforms:submission id="save-config" ref="instance('config-template')" action="{instance('exist-url')}{instance('control-instance')/collection-name}/config.xml" method="put" replace="none"
				xxforms:username="admin" xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving Config.</xforms:message>
				<xforms:send submission="load-config" ev:event="xforms-submit-done"/>
			</xforms:submission>

			<xforms:submission id="save-imports" ref="instance('imports-template')" action="{instance('exist-url')}{instance('control-instance')/collection-name}/imports.xml" method="put"
				replace="none" xxforms:username="admin" xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error Saving Import XML.</xforms:message>
			</xforms:submission>

			<xforms:submission id="add-object-collection" ref="instance('create-object-collection')" method="post" action="{instance('exist-url')}" replace="none" xxforms:username="admin"
				xxforms:password=""/>

			<!-- delete coin -->
			<xforms:submission id="delete-object" action="{instance('exist-url')}{instance('control-instance')/collection-name}/objects/{instance('id')}.xml" method="delete" replace="none"
				xxforms:username="admin" xxforms:password="">
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('control-instance')/status">Object successfully deleted.</xforms:setvalue>
			</xforms:submission>

			<!-- load object temporarily -->
			<xforms:submission id="load-object" serialization="none" method="get" action="{instance('exist-url')}{instance('control-instance')/collection-name}/objects/{instance('id')}.xml"
				replace="instance" instance="object" xxforms:username="admin" xxforms:password="">
				<xforms:message ev:event="xforms-submit-error" level="modal">Cannot load object: <xforms:output ref="instance('id')"/></xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<!-- if the record is NUDS -->
					<xforms:action if="instance('object')/local-name() = 'nuds'">
						<xforms:insert nodeset="instance('addIndex')" origin="xxforms:call-xpl('oxf:/apps/numishare/xpl/nuds-to-solr-private.xpl', 'data', instance('object'), 'data')"/>
					</xforms:action>
					<xforms:action if="instance('object')/local-name() = 'nudsHoard'">
						<xforms:insert nodeset="instance('addIndex')" origin="xxforms:call-xpl('oxf:/apps/numishare/xpl/nudsHoard-to-solr-private.xpl', 'data', instance('object'), 'data')"/>
					</xforms:action>
					<xforms:insert context="instance('addIndex')/doc" origin="instance('collection-field')"/>
					<xforms:setvalue ref="instance('addIndex')/doc/field[@name='collection-name']" value="instance('control-instance')/collection-name"/>
					<xforms:send submission="post-solr-doc"/>
				</xforms:action>
			</xforms:submission>
			<!-- ************************* SOLR SUBMISSIONS ************************** -->
			<!-- query Solr for the id of all currently published documents and repost them to solr -->
			<xforms:submission id="republish" serialization="none" method="get"
				action="{instance('control-instance')/solr-core}select/?q=collection-name:{instance('control-instance')/collection-name}&amp;rows=100000&amp;start=0&amp;fl=id" replace="instance"
				instance="list-published-response">
				<xforms:message ev:event="xforms-submit-error" level="modal">Solr is inaccessible. Please check Solr configuration. [ADM001]</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
					<xforms:setvalue ref="instance('control-instance')/identifiers" value="string-join(instance('list-published-response')//doc/str[@name='id'], '|')"/>

					<!-- get Solr document -->
					<xforms:send submission="generate-add-document"/>
				</xforms:action>
			</xforms:submission>
			<!-- access service to read in pre-transformed solr doc -->
			<xforms:submission id="nuds-to-solr" method="get" replace="instance" instance="addIndex" serialization="none" resource="{instance('config')/url}id/{instance('id')}.solr">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error transforming XML record to Solr document.</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:send submission="post-solr-doc"/>
				</xforms:action>
			</xforms:submission>
			<!-- post instance to Solr -->
			<xforms:submission id="post-solr-doc" action="{instance('control-instance')/solr-core}update" ref="instance('addIndex')" instance="addIndex" replace="instance" method="post">
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr. Index may be offline or URL is incorrect.</xforms:message>
			</xforms:submission>
			<!-- delete from Solr -->
			<xforms:submission id="delete-solr-doc" action="{instance('control-instance')/solr-core}update" ref="instance('deleteId')" instance="deleteId" replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
				<xforms:message ev:event="xforms-submit-error" level="modal">Data Failed to POST to Solr.</xforms:message>
			</xforms:submission>
			<xforms:submission id="delete-all" action="{instance('control-instance')/solr-core}update" ref="instance('deleteAll')" instance="deleteAll" replace="none" method="post">
				<xforms:send ev:event="xforms-submit-done" submission="submit-commit"/>
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('control-instance')/status">Objects removed from search index.</xforms:setvalue>
			</xforms:submission>

			<!-- pass identifiers URL parameter to xquery process in Cocoon to generate large Solr add document -->
			<xforms:submission id="generate-add-document" method="get" replace="instance" instance="addIndex" serialization="none"
				resource="{instance('config')/url}ingest?identifiers={instance('control-instance')/identifiers}">
				<xforms:message ev:event="xforms-submit-error" level="modal">Error getting Solr document from Cocoon xquery pipeline.</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:send submission="post-solr-doc"/>
					<xforms:send submission="submit-commit"/>

					<!-- optimize index -->
					<xforms:send submission="optimize"/>
					<!-- reload table -->
					<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
					<xforms:delete nodeset="instance('list')/*"/>
					<xforms:send submission="query-solr"/>
				</xforms:action>
			</xforms:submission>

			<!-- send commit -->
			<xforms:submission id="submit-commit" action="{instance('control-instance')/solr-core}update" ref="instance('sendCommit')" instance="sendCommit" replace="none" method="post">
				<xforms:message ev:event="xforms-submit-error" level="modal">Failed to commit to Solr index.</xforms:message>
			</xforms:submission>

			<!-- send optimize -->
			<xforms:submission id="optimize" action="{instance('control-instance')/solr-core}update" ref="instance('optimizeIndex')" instance="optimizeIndex" replace="none" method="post">
				<xforms:message ev:event="xforms-submit-error" level="modal">Failed to optimize Solr index.</xforms:message>
			</xforms:submission>

			<!-- get 20 search results, depending on page -->
			<xforms:submission id="query-solr" serialization="none" method="get"
				action="{instance('control-instance')/solr-core}select/?q=collection-name:{instance('control-instance')/collection-name} AND {instance('control-instance')/solr-query}&amp;rows=20&amp;start={(instance('control-instance')/page - 1) * 20}"
				replace="instance" instance="all-response">
				<xforms:message ev:event="xforms-submit-error" level="modal">Solr is inaccessible. Please check Solr configuration.</xforms:message>
				<xforms:action ev:event="xforms-submit-done">
					<xforms:action xxforms:iterate="instance('all-response')//doc">
						<xxforms:variable name="id" select="str[@name='id']"/>
						<xforms:setvalue ref="instance('id')" value="$id"/>
						<xforms:insert context="instance('list')" nodeset="./child::node()[last()]" origin="instance('item-template')"/>
						<xforms:setvalue ref="instance('list')/item[last()]/title" value="context()/str[@name='title_display']"/>
						<xforms:setvalue ref="instance('list')/item[last()]/id" value="$id"/>
						<xforms:setvalue ref="instance('list')/item[last()]/recordType" value="context()/str[@name='recordType']"/>
						<xforms:setvalue ref="instance('list')/item[last()]/obverseLegend" value="context()/str[@name='obv_leg_display']"/>
						<xforms:setvalue ref="instance('list')/item[last()]/obverseType" value="context()/str[@name='obv_type_display']"/>
						<xforms:setvalue ref="instance('list')/item[last()]/reverseLegend" value="context()/str[@name='rev_leg_display']"/>
						<xforms:setvalue ref="instance('list')/item[last()]/reverseType" value="context()/str[@name='rev_type_display']"/>
						<xforms:setvalue ref="instance('list')/item[last()]/thumbnail_obv" value="context()/str[@name='thumbnail_obv']"/>
						<xforms:setvalue ref="instance('list')/item[last()]/thumbnail_rev" value="context()/str[@name='thumbnail_rev']"/>
						<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
						<xforms:send submission="query-solr-for-publication"/>
					</xforms:action>
				</xforms:action>
			</xforms:submission>

			<!-- submission to query solr to see if the document is published -->
			<xforms:submission id="query-solr-for-publication" serialization="none" method="get"
				action="{instance('control-instance')/solr-core}select/?q=collection-name:{instance('control-instance')/collection-name} AND id:&#x022;{instance('id')}&#x022;" replace="instance"
				instance="published-response">
				<!-- if the document is found in solr, get the updated solr doc -->
				<xforms:setvalue ev:event="xforms-submit-done" if="instance('published-response')/result[@name='response']/@numFound = '1'" ref="instance('list')/item[last()]/published" value="'true'"
				/>
			</xforms:submission>
			<xforms:submission id="query-all-docs" serialization="none" method="get"
				action="{instance('control-instance')/solr-core}select/?q=collection-name:{instance('control-instance')/collection-name} AND fulltext:*&amp;rows=0" replace="instance"
				instance="query-all-response">
				<xforms:setvalue ref="instance('control-instance')/error" ev:event="xforms-submit-error">Solr is inaccessible. Please check Solr configuration.</xforms:setvalue>
			</xforms:submission>

			<!-- ************************* MODEL CONSTRUCTION ************************** -->
			<xforms:action ev:event="xforms-model-construct-done">
				<!-- load numishare config file on xforms construction -->
				<xforms:insert context="instance('control-instance')" nodeset="collection-name" position="after"
					origin="xxforms:call-xpl('oxf:/apps/numishare/xpl/get-authentication.xpl', 'dump', instance('dump'), 'data')"/>
				<xforms:send submission="load-collections"/>
			</xforms:action>
		</xforms:model>
		<!--<xi:include href="oxf:/xbl/numishare/publish-all/publish-all.xbl" xi:omit-xml-base="true"/>-->
	</xhtml:head>
	<xhtml:body class="yui-skin-sam">
		<xhtml:div id="doc4" class="yui-t2 content ui-corner-all">
			<xxforms:variable name="display_path">./</xxforms:variable>
			<xi:include href="header.xml"/>
			<div id="bd">
				<xhtml:div id="form">
					<xforms:action ev:event="xforms-enabled" if="not(string(instance('control-instance')/collection-name))">
						<xxforms:show dialog="create-collection"/>
					</xforms:action>
					<xforms:action ev:event="xforms-enabled" if="instance('config-template')/firstrun = 'true'">
						<xxforms:show dialog="firstrun"/>
					</xforms:action>
					<xxforms:dialog id="create-collection" appearance="full" level="modal" close="false" draggable="true" visible="false">
						<xforms:label>Welcome to Numishare</xforms:label>
						<xhtml:p>Please create a collection for your authenticated group.</xhtml:p>
						<xforms:group ref="instance('collections-list')">
							<xhtml:h3><xforms:output ref="instance('control-instance')/request-security/role"/></xhtml:h3>
							<div>
								<xforms:input ref="collection[@role=instance('control-instance')/request-security/role]/@name">
									<xforms:label>Collection Name</xforms:label>
									<xforms:alert>Required</xforms:alert>
								</xforms:input>
							</div>
						</xforms:group>
						<xforms:trigger>
							<xforms:label>Save</xforms:label>
							<xforms:action ev:event="DOMActivate">
								<xforms:setvalue ref="instance('control-instance')/collection-name"
									value="instance('collections-list')/collection[@role=instance('control-instance')/request-security/role]/@name"/>
								<!-- set exist collection value for creating new collection-->
								<xforms:setvalue ref="instance('create-object-collection')/exist:text"
									value="concat(&quot;xmldb:create-collection(&#x0027;/db/&quot;, instance(&quot;control-instance&quot;)/collection-name, &quot;&#x0027;, &#x0027;objects&#x0027;)&quot;)"/>
								<!-- set the delete all query -->
								<xforms:setvalue ref="instance('deleteAll')/query" value="concat('collection-name:', instance('control-instance')/collection-name)"/>
								<xforms:send submission="save-collections"/>
								<xforms:send submission="load-config"/>
								<xxforms:hide dialog="create-collection"/>
								<xxforms:show dialog="firstrun" if="instance('config-template')/firstrun = 'true'"/>
							</xforms:action>
						</xforms:trigger>
					</xxforms:dialog>
					<xxforms:dialog id="firstrun" appearance="full" level="modal" close="false" draggable="true" visible="false">
						<xforms:label>Welcome to Numishare</xforms:label>
						<xhtml:p>This is the first time you have run Numishare.<xhtml:br/>Please set the following fields (they can be changed later under "Settings")</xhtml:p>
						<xforms:group ref="instance('config-template')">
							<xhtml:h3>Boilerplate</xhtml:h3>
							<div>
								<xforms:input ref="title">
									<xforms:label>Site Title</xforms:label>
									<xforms:alert>Required</xforms:alert>
								</xforms:input>
							</div>
							<div>
								<xforms:input ref="description">
									<xforms:label>Site Description</xforms:label>
									<xforms:alert>Required</xforms:alert>
								</xforms:input>
							</div>
							<div>
								<xforms:input ref="template/publisher">
									<xforms:label>Publisher</xforms:label>
									<xforms:alert>Required</xforms:alert>
								</xforms:input>
							</div>
							<div>
								<xforms:input ref="template/copyrightHolder">
									<xforms:label>Copyright Holder</xforms:label>
									<xforms:alert>Required</xforms:alert>
								</xforms:input>
							</div>
							<div>
								<xforms:select1 ref="template/language">
									<xforms:label>Language of Record</xforms:label>
									<xforms:item>
										<xforms:label>Select Language...</xforms:label>
										<xforms:value/>
									</xforms:item>
									<xforms:itemset nodeset="instance('languageselect-template')//language">
										<xforms:label ref="name"/>
										<xforms:value ref="name"/>
									</xforms:itemset>
									<xforms:alert>Required</xforms:alert>
									<xxforms:variable name="language" select="."/>
									<xforms:setvalue ref="@langcode" value="instance('languageselect-template')//language[name = $language]/code" ev:event="xforms-value-changed"/>
								</xforms:select1>
							</div>
							<xhtml:h3>URLS</xhtml:h3>
							<div>
								<xforms:input ref="url">
									<xforms:label>Public Site</xforms:label>
									<xforms:alert>Required, must be a URL</xforms:alert>
								</xforms:input>
							</div>
							<div>
								<xforms:input ref="solr_published">
									<xforms:label>Solr Published</xforms:label>
									<xforms:alert>Required, must be a URL</xforms:alert>
								</xforms:input>
							</div>
							<div>
								<xforms:input ref="solr_all">
									<xforms:label>Solr All</xforms:label>
									<xforms:alert>Required, must be a URL</xforms:alert>
								</xforms:input>
							</div>
						</xforms:group>
						<xforms:trigger>
							<xforms:label>Save</xforms:label>
							<xforms:action ev:event="DOMActivate">
								<xforms:setvalue ref="instance('config-template')/firstrun" value="'false'"/>
								<xforms:send submission="save-imports"/>
								<xforms:send submission="add-object-collection"/>
								<xforms:send submission="save-config"/>
								<xxforms:hide dialog="firstrun"/>
							</xforms:action>
						</xforms:trigger>
					</xxforms:dialog>
					<xforms:group ref="instance('control-instance')/status/text()">
						<xhtml:div class="success">
							<xforms:output ref="instance('control-instance')/status"/>
						</xhtml:div>
					</xforms:group>
					<xforms:group ref="instance('control-instance')/error/text()">
						<xhtml:div class="error">
							<xforms:output ref="instance('control-instance')/error"/>
						</xhtml:div>
					</xforms:group>
					<xhtml:h2>Object Management</xhtml:h2>
					<xhtml:ul>
						<xhtml:li>
							<xhtml:a href="edit/coin/">Create New Coin or Medal</xhtml:a>
						</xhtml:li>
						<xhtml:li>
							<xhtml:a href="edit/object/">Create New Non-Coin Object</xhtml:a>
						</xhtml:li>
					</xhtml:ul>
					<xhtml:h2>Publication</xhtml:h2>
					<xhtml:ul>
						<xhtml:li>
							<xforms:trigger appearance="minimal">
								<xforms:label>Publish All Objects</xforms:label>
								<xforms:dispatch target="publish-all" name="fr-show" ev:event="DOMActivate"/>
							</xforms:trigger>
						</xhtml:li>
						<xhtml:li>
							<xforms:trigger appearance="minimal">
								<xforms:label>Reindex Published Objects</xforms:label>
								<xforms:dispatch target="republish-dialog" name="fr-show" ev:event="DOMActivate"/>
							</xforms:trigger>
						</xhtml:li>
						<xhtml:li>
							<xforms:trigger appearance="minimal">
								<xforms:label>Unpublish All Objects</xforms:label>
								<xforms:dispatch target="unpublish-all" name="fr-show" ev:event="DOMActivate"/>
							</xforms:trigger>
						</xhtml:li>
					</xhtml:ul>
					<xforms:group ref="instance('list')">
						<xforms:group ref=".[count(item) &gt; 0]">
							<xhtml:h3>List of Objects</xhtml:h3>
							<xhtml:div>
								<xforms:input ref="instance('control-instance')/solr-query"/>
								<xforms:trigger>
									<xforms:label>Search</xforms:label>
									<xforms:action ev:event="DOMActivate">
										<xforms:delete nodeset="instance('list')/*"/>
										<xforms:setvalue ref="instance('control-instance')/page">1</xforms:setvalue>
										<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
										<xforms:send submission="query-solr"/>
									</xforms:action>
								</xforms:trigger>
								<xforms:group ref=".[instance('control-instance')/solr-query != 'fulltext:*']">
									<xforms:trigger>
										<xforms:label>Clear</xforms:label>
										<xforms:action ev:event="DOMActivate">
											<xforms:delete nodeset="instance('list')/*"/>
											<xforms:setvalue ref="instance('control-instance')/solr-query">fulltext:*</xforms:setvalue>
											<xforms:setvalue ref="instance('control-instance')/page">1</xforms:setvalue>
											<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
											<xforms:send submission="query-solr"/>
										</xforms:action>
									</xforms:trigger>
								</xforms:group>
							</xhtml:div>
							<!-- pagination variables -->
							<xxforms:variable name="numFound" select="instance('all-response')/result/@numFound"/>
							<xxforms:variable name="page" select="number(instance('control-instance')/page)"/>
							<xxforms:variable name="next" select="$page + 1"/>
							<xxforms:variable name="previous" select="if ($page &gt;= 1) then $page - 1 else 1"/>
							<xxforms:variable name="current" select="$page"/>
							<xxforms:variable name="total" select="ceiling($numFound div 20)"/>
							<!-- pagination -->
							<xhtml:div class="paging_div">
								<xhtml:div style="float:left;"> Displaying records <xhtml:b>
										<xforms:output value="(($page - 1) * 20) + 1"/>
									</xhtml:b> to <xhtml:b>
										<xforms:output value="if ($numFound &gt; $page * 20) then $page * 20 else $numFound"/>
									</xhtml:b> of <xhtml:b>
										<xforms:output value="$numFound"/>
									</xhtml:b> total results.</xhtml:div>
								<xhtml:div style="float:right;">
									<xforms:group ref=".[$page &gt; 1]">
										<xforms:trigger appearance="minimal">
											<xforms:label>«Previous</xforms:label>
											<xforms:action ev:event="DOMActivate">
												<xforms:delete nodeset="instance('list')/*"/>
												<xforms:setvalue ref="instance('control-instance')/page" value="$previous"/>
												<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
												<xforms:send submission="query-solr"/>
											</xforms:action>
										</xforms:trigger>
									</xforms:group>
									<xforms:group ref=".[$page = 1]">
										<xhtml:span class="pagingSep">«Previous</xhtml:span>
									</xforms:group>
									<!-- always display links to the first two pages -->
									<xforms:group ref=".[$page &gt; 3]">
										<xforms:trigger appearance="minimal">
											<xforms:label>1</xforms:label>
											<xforms:action ev:event="DOMActivate">
												<xforms:delete nodeset="instance('list')/*"/>
												<xforms:setvalue ref="instance('control-instance')/page" value="1"/>
												<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
												<xforms:send submission="query-solr"/>
											</xforms:action>
										</xforms:trigger>
									</xforms:group>
									<xforms:group ref=".[$page &gt; 4]">
										<xforms:trigger appearance="minimal">
											<xforms:label>2</xforms:label>
											<xforms:action ev:event="DOMActivate">
												<xforms:delete nodeset="instance('list')/*"/>
												<xforms:setvalue ref="instance('control-instance')/page" value="2"/>
												<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
												<xforms:send submission="query-solr"/>
											</xforms:action>
										</xforms:trigger>
									</xforms:group>
									<!-- display only if you are on page 6 or greater -->
									<xforms:group ref=".[$page &gt; 5]">
										<xhtml:span class="pagingSep">...</xhtml:span>
									</xforms:group>
									<!-- always display links to the previous two pages -->
									<xforms:group ref=".[$page &gt; 2]">
										<xforms:trigger appearance="minimal">
											<xforms:label>
												<xforms:output value="$page - 2"/>
											</xforms:label>
											<xforms:action ev:event="DOMActivate">
												<xforms:delete nodeset="instance('list')/*"/>
												<xforms:setvalue ref="instance('control-instance')/page" value="$page - 2"/>
												<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
												<xforms:send submission="query-solr"/>
											</xforms:action>
										</xforms:trigger>
									</xforms:group>
									<xforms:group ref=".[$page &gt; 1]">
										<xforms:trigger appearance="minimal">
											<xforms:label>
												<xforms:output value="$page - 1"/>
											</xforms:label>
											<xforms:action ev:event="DOMActivate">
												<xforms:delete nodeset="instance('list')/*"/>
												<xforms:setvalue ref="instance('control-instance')/page" value="$page - 1"/>
												<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
												<xforms:send submission="query-solr"/>
											</xforms:action>
										</xforms:trigger>
									</xforms:group>
									<!-- current page -->
									<xhtml:span class="pagingBtn">
										<xforms:output value="$current"/>
									</xhtml:span>
									<!-- next two pages -->
									<xforms:group ref=".[$page + 1 &lt;= $total]">
										<xforms:trigger appearance="minimal">
											<xforms:label>
												<xforms:output value="$page + 1"/>
											</xforms:label>
											<xforms:action ev:event="DOMActivate">
												<xforms:delete nodeset="instance('list')/*"/>
												<xforms:setvalue ref="instance('control-instance')/page" value="$page + 1"/>
												<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
												<xforms:send submission="query-solr"/>
											</xforms:action>
										</xforms:trigger>
									</xforms:group>
									<xforms:group ref=".[$page + 2 &lt;= $total]">
										<xforms:trigger appearance="minimal">
											<xforms:label>
												<xforms:output value="$page + 2"/>
											</xforms:label>
											<xforms:action ev:event="DOMActivate">
												<xforms:delete nodeset="instance('list')/*"/>
												<xforms:setvalue ref="instance('control-instance')/page" value="$page + 2"/>
												<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
												<xforms:send submission="query-solr"/>
											</xforms:action>
										</xforms:trigger>
									</xforms:group>
									<!-- separator -->
									<xforms:group ref=".[$page &lt;= $total - 4]">
										<xhtml:span class="pagingSep">...</xhtml:span>
									</xforms:group>
									<!-- last two pages -->
									<xforms:group ref=".[$page &lt;= $total - 4]">
										<xforms:trigger appearance="minimal">
											<xforms:label>
												<xforms:output value="$total - 1"/>
											</xforms:label>
											<xforms:action ev:event="DOMActivate">
												<xforms:delete nodeset="instance('list')/*"/>
												<xforms:setvalue ref="instance('control-instance')/page" value="$total - 1"/>
												<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
												<xforms:send submission="query-solr"/>
											</xforms:action>
										</xforms:trigger>
									</xforms:group>
									<xforms:group ref=".[$page &lt;= $total - 3]">
										<xforms:trigger appearance="minimal">
											<xforms:label>
												<xforms:output value="$total"/>
											</xforms:label>
											<xforms:action ev:event="DOMActivate">
												<xforms:delete nodeset="instance('list')/*"/>
												<xforms:setvalue ref="instance('control-instance')/page" value="$total"/>
												<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
												<xforms:send submission="query-solr"/>
											</xforms:action>
										</xforms:trigger>
									</xforms:group>
									<!-- next page -->
									<xforms:group ref=".[$total &gt; $current]">
										<xforms:trigger appearance="minimal">
											<xforms:label>Next»</xforms:label>
											<xforms:action ev:event="DOMActivate">
												<xforms:delete nodeset="instance('list')/*"/>
												<xforms:setvalue ref="instance('control-instance')/page" value="$next"/>
												<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
												<xforms:send submission="query-solr"/>
											</xforms:action>
										</xforms:trigger>
									</xforms:group>
									<xforms:group ref=".[not($total &gt; $current)]">
										<xhtml:span class="pagingSep">Next»</xhtml:span>
									</xforms:group>
								</xhtml:div>
							</xhtml:div>
							<xhtml:table style="width:100%">
								<xhtml:thead>
									<xhtml:tr>
										<xhtml:th style="width:79%">Title</xhtml:th>
										<xhtml:th style="width:8%">Public<br/>View</xhtml:th>
										<!--<xhtml:th style="width:8%">Private<br/>View</xhtml:th>-->
										<xhtml:th style="width:8%">Publish</xhtml:th>
										<xhtml:th style="width:5%">Delete</xhtml:th>
									</xhtml:tr>
								</xhtml:thead>
								<xhtml:tbody>
									<xforms:repeat nodeset="instance('list')/item">
										<xxforms:variable name="id" select="id"/>
										<xxforms:variable name="class" select="if (position() mod 2 = 0) then 'even-row' else 'odd-row'"/>
										<xhtml:tr>
											<xhtml:td class="{$class}">
												<div class="result_metadata">
													<xhtml:h4>
														<xhtml:a href="edit/coin/?id={$id}">
															<xforms:output ref="title"/>
															<xforms:output ref="concat(' (', $id, ')')"/>
														</xhtml:a>
													</xhtml:h4>
													<dl>
														<div>
															<dt>Record Type: </dt>
															<dd style="margin-left:150px;">
																<xforms:output ref="recordType"/>
															</dd>
														</div>
														<xforms:group ref=".[string(obverseLegend) or string(obverseType)]">
															<div>
																<dt>Obverse:</dt>
																<dd style="margin-left:150px;">
																	<xforms:output ref="obverseType"/>
																	<xforms:group ref=".[string(obverseLegend) and string(obverseType)]">
																		<span>: </span>
																	</xforms:group>
																	<xforms:output ref="obverseLegend"/>
																</dd>
															</div>
														</xforms:group>
														<xforms:group ref=".[string(reverseLegend) or string(reverseType)]">
															<div>
																<dt>Reverse:</dt>
																<dd style="margin-left:150px;">
																	<xforms:output ref="reverseType"/>
																	<xforms:group ref=".[string(reverseLegend) and string(reverseType)]">
																		<span>: </span>
																	</xforms:group>
																	<xforms:output ref="reverseLegend"/>
																</dd>
															</div>
														</xforms:group>
													</dl>
												</div>
												<div style="float:right">
													<xforms:group ref=".[string(thumbnail_obv)]">
														<xforms:output mediatype="image/*" value="concat(instance('config')/url, thumbnail_obv)"/>
													</xforms:group>
													<xforms:group ref=".[string(thumbnail_rev)]">
														<xforms:output mediatype="image/*" value="concat(instance('config')/url, thumbnail_rev)"/>
													</xforms:group>
												</div>
											</xhtml:td>
											<xhtml:td class="{$class} center"><xhtml:a href="{instance('config')/url}id/{$id}.xml" target="_blank">xml</xhtml:a> | <xhtml:a
													href="{instance('config')/url}id/{$id}" target="_blank">html</xhtml:a></xhtml:td>
											<!--<xhtml:td class="{$class} center"><xhtml:a href="id/{$id}.xml" target="_blank">xml</xhtml:a> | <xhtml:a href="show/{$id}" target="_blank"
												>html</xhtml:a></xhtml:td>-->
											<xhtml:td class="{$class} center">
												<xforms:group ref=".[published = 'true']">
													<xforms:trigger appearance="minimal">
														<xforms:label>unpublish</xforms:label>
														<xforms:dispatch target="unpublish" name="fr-show" ev:event="DOMActivate"/>
													</xforms:trigger>
												</xforms:group>
												<xforms:group ref=".[published != 'true']">
													<xforms:trigger appearance="minimal">
														<xforms:label>publish</xforms:label>
														<xforms:dispatch target="publish" name="fr-show" ev:event="DOMActivate"/>
													</xforms:trigger>
												</xforms:group>
											</xhtml:td>
											<xhtml:td class="{$class} center">
												<xforms:trigger appearance="minimal">
													<xforms:label>
														<xhtml:img src="{$display_path}images/remove.gif"/>
													</xforms:label>
													<xforms:dispatch target="delete" name="fr-show" ev:event="DOMActivate"/>
												</xforms:trigger>
											</xhtml:td>
										</xhtml:tr>
										<!-- dialogs -->
										<fr:alert-dialog id="publish">
											<fr:label>Publish</fr:label>
											<fr:message>Do you want to publish this object to the search index?</fr:message>
											<fr:negative-choice/>
											<fr:positive-choice>
												<xforms:action ev:event="DOMActivate">
													<xforms:setvalue ref="instance('id')" value="$id"/>
													<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
													<xforms:send submission="nuds-to-solr"/>
													<xforms:send submission="submit-commit"/>
													<!-- reload table -->
													<xforms:delete nodeset="instance('list')/*"/>
													<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
													<xforms:send submission="query-solr"/>
												</xforms:action>
											</fr:positive-choice>
										</fr:alert-dialog>
										<fr:alert-dialog id="unpublish">
											<fr:label>Unpublish</fr:label>
											<fr:message>Do you want to remove this object from the search index?</fr:message>
											<fr:negative-choice/>
											<fr:positive-choice>
												<xforms:action ev:event="DOMActivate">
													<xforms:setvalue ref="instance('deleteId')/id" value="$id"/>
													<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
													<xforms:send submission="delete-solr-doc"/>
													<!-- reload table -->
													<xforms:delete nodeset="instance('list')/*"/>
													<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
													<xforms:send submission="query-solr"/>
												</xforms:action>
											</fr:positive-choice>
										</fr:alert-dialog>
										<fr:alert-dialog id="delete">
											<fr:label>Delete</fr:label>
											<fr:message>Are you sure you want to delete this object?</fr:message>
											<fr:negative-choice/>
											<fr:positive-choice>
												<xforms:action ev:event="DOMActivate">
													<xforms:setvalue ref="instance('deleteId')/id" value="$id"/>
													<xforms:setvalue ref="instance('id')" value="$id"/>
													<xforms:send submission="delete-object"/>
													<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
													<xforms:send submission="delete-solr-doc"/>
													<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
													<xforms:send submission="delete-solr-doc"/>
													<!-- reload table -->
													<xforms:delete nodeset="instance('list')/*"/>
													<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
													<xforms:send submission="query-solr"/>
												</xforms:action>
											</fr:positive-choice>
										</fr:alert-dialog>
									</xforms:repeat>
								</xhtml:tbody>
							</xhtml:table>
						</xforms:group>
						<xforms:group ref=".[count(item)=0]">
							<xforms:group ref=".[instance('control-instance')/solr-query = 'fulltext:*']">
								<xhtml:h1>No objects in collection.</xhtml:h1>
							</xforms:group>
							<xforms:group ref=".[instance('control-instance')/solr-query != 'fulltext:*']">
								<xhtml:h1>No objects that match query: <xforms:output ref="instance('control-instance')/solr-query"/>-- <xforms:trigger appearance="minimal">
										<xforms:label>clear</xforms:label>
										<xforms:action ev:event="DOMActivate">
											<xforms:delete nodeset="instance('list')/*"/>
											<xforms:setvalue ref="instance('control-instance')/solr-query">fulltext:*</xforms:setvalue>
											<xforms:setvalue ref="instance('control-instance')/page">1</xforms:setvalue>
											<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
											<xforms:send submission="query-solr"/>
										</xforms:action>
									</xforms:trigger></xhtml:h1>
							</xforms:group>
						</xforms:group>
					</xforms:group>
				</xhtml:div>
			</div>

			<!-- mass publication dialogs -->
			<fr:alert-dialog id="publish-all">
				<fr:label>Publish All</fr:label>
				<fr:message>Do you want to publish all objects? This may take several minutes.</fr:message>
				<fr:negative-choice/>
				<fr:positive-choice>
					<xforms:action ev:event="DOMActivate">
						<!-- get count for NUDS records -->
						<xforms:setvalue ref="instance('eXist-xquery')/exist:text">&lt;report&gt;{count(collection()/*[local-name()='nuds'])}&lt;/report&gt;</xforms:setvalue>
						<xforms:send submission="xquery-collection"/>
						<xforms:setvalue ref="instance('control-instance')/nuds-count" value="instance('collection-result')/report"/>
						<!-- get count for NUDS Hoard Records -->
						<xforms:setvalue ref="instance('eXist-xquery')/exist:text">&lt;report&gt;{count(collection()/*[local-name()='nudsHoard'])}&lt;/report&gt;</xforms:setvalue>
						<xforms:send submission="xquery-collection"/>
						<xforms:setvalue ref="instance('control-instance')/nh-count" value="instance('collection-result')/report"/>
						
						<!-- if nh-count is greater than 0, process 100 hoard records at a time -->
						<xforms:action if="number(instance('control-instance')/nh-count) &gt; 0">
							<xforms:setvalue ref="instance('eXist-xquery')/exist:text">&lt;report> { for $i at $position in collection()  return 
							concat(substring-before(substring-after(document-uri($i), 'objects/'), '.xml'), if ($position mod 100 = 0) then ',' else '|') } &lt;/report></xforms:setvalue>
							<xforms:send submission="xquery-collection"/>
							<xxforms:variable name="tokens" select="tokenize(replace(instance('collection-result')/report, ' ', ''), ',')"/>
							<xforms:action xxforms:iterate="$tokens">
								<xforms:setvalue ref="instance('control-instance')/identifiers" value="context()"/>
								<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
								<!-- get Solr document -->
								<xforms:send submission="generate-add-document"/>
							</xforms:action>
						</xforms:action>
						
						<!-- if nuds-count is greater than 0, process 5000 coin or coin-type records at a time -->
						<xforms:action if="number(instance('control-instance')/nuds-count) &gt; 0">
							<xforms:setvalue ref="instance('eXist-xquery')/exist:text">&lt;report> { for $i at $position in collection()  return 
								concat(substring-before(substring-after(document-uri($i), 'objects/'), '.xml'), if ($position mod 5000 = 0) then ',' else '|') } &lt;/report></xforms:setvalue>
							<xforms:send submission="xquery-collection"/>
							<xxforms:variable name="tokens" select="tokenize(replace(instance('collection-result')/report, ' ', ''), ',')"/>
							<xforms:action xxforms:iterate="$tokens">
								<xforms:setvalue ref="instance('control-instance')/identifiers" value="context()"/>
								<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
								<!-- get Solr document -->
								<xforms:send submission="generate-add-document"/>
							</xforms:action>
						</xforms:action>
					</xforms:action>
				</fr:positive-choice>
			</fr:alert-dialog>
			<fr:alert-dialog id="unpublish-all">
				<fr:label>Unpublish All</fr:label>
				<fr:message>Do you want to unpublish all objects?</fr:message>
				<fr:negative-choice/>
				<fr:positive-choice>
					<xforms:action ev:event="DOMActivate">
						<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
						<xforms:setvalue ref="instance('deleteAll')/query" value="concat('collection-name:', instance('control-instance')/collection-name)"/>
						<xforms:send submission="delete-all" ev:event="DOMActivate"/>

						<!-- optimize index -->
						<xforms:send submission="optimize"/>
						<!-- reload table -->
						<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_all"/>
						<xforms:delete nodeset="instance('list')/*"/>
						<xforms:send submission="query-solr"/>
					</xforms:action>
				</fr:positive-choice>
			</fr:alert-dialog>
			<fr:alert-dialog id="republish-dialog">
				<fr:label>Republish</fr:label>
				<fr:message>Do you want to reindex currently published objects?</fr:message>
				<fr:negative-choice/>
				<fr:positive-choice>
					<xforms:action ev:event="DOMActivate">
						<xforms:setvalue ref="instance('control-instance')/solr-core" value="instance('config')/solr_published"/>
						<xforms:send submission="republish"/>
						<xforms:send submission="optimize" ev:event="xforms-submit-done"/>
					</xforms:action>
				</fr:positive-choice>
			</fr:alert-dialog>

			<!--<widget:xforms-instance-inspector id="orbeon-xforms-inspector" xmlns:widget="http://orbeon.org/oxf/xml/widget"/>-->

		</xhtml:div>
	</xhtml:body>
</xhtml:html>
